package sjtu.ist.warehouse4ws.action;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import sjtu.ist.warehouse4ws.service.OplogService;
import sjtu.ist.warehouse4ws.tool.ListPage;
import sjtu.ist.warehouse4ws.vo.OplogVO;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class OplogAction extends ActionSupport{
	private OplogService oplogService;
	private List<OplogVO> oplogList = new ArrayList<OplogVO>();
	
	//private String id;
	
	private String user;
	private String after;
	private String before;
	private String file;
	private String operation;
	private String dspt;
	
	private int start;
	private int limit;
	private int count;
	
	//搜索记录
	public String searchOplog(){
		try {
			if(user != null)
			{
			user = new String(user.getBytes("ISO-8859-1"), "UTF-8"); 
			}
			if(file != null)
			{
			file = new String(file.getBytes("ISO-8859-1"), "UTF-8");
			}
			//keyWord3 = new String(keyWord3.getBytes("ISO-8859-1"), "UTF-8");
			if(dspt != null){
			dspt = new String(dspt.getBytes("ISO-8859-1"), "UTF-8"); 
			}
			//keyWord6 = new String(keyWord6.getBytes("ISO-8859-1"), "UTF-8"); 
			} catch (UnsupportedEncodingException e) { 
			// TODO 自动生成 catch 块 
			e.printStackTrace(); 
			} 
		ListPage lp=oplogService.searchOplog(user, after, before, file, operation, dspt,start,limit);
		oplogList=lp.list;
		count=lp.total;
		return SUCCESS;
	}
	
	//显示所有记录
	public String showOplogList(){
		ListPage lp=oplogService.getOplogVOList(start,limit);
		oplogList=lp.list;
		count=lp.total;
		return SUCCESS;
	}

	@JSON(name = "totalOplog")
	public int getTotalOplog() {
		//return this.oplogList.size();
		return count;
	}

	@JSON(name = "Oplog")
	public List<OplogVO> getOplogList() {
		return this.oplogList;
	}

	// 注入OplogService
	public void setOplogService(OplogService oplogService) {
		this.oplogService = oplogService;
	}

	public String getAfter() {
		return after;
	}

	public void setAfter(String after) {
		this.after = after;
	}

	public String getBefore() {
		return before;
	}

	public void setBefore(String before) {
		this.before = before;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}

	public String getDspt() {
		return dspt;
	}

	public void setDspt(String dspt) {
		this.dspt = dspt;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

//	public void setId(String id) {
//		this.id = id;
//	}
}